package ee.ut.maxorato_macobo.oop.mud.network;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import ee.ut.maxorato_macobo.oop.mud.GameMain;

public final class NetEventQueue {
	private static final BlockingQueue<NetEvent> eventQueue = new LinkedBlockingQueue<NetEvent>();

	public static void add(NetEvent event) {
		eventQueue.add(event);
	}
	
	public static void process() {
        try {
            NetEvent event = eventQueue.poll(GameMain.getNanosToTick(), TimeUnit.NANOSECONDS);
            
            if(event == null) {
            	GameMain.doTick();
            }
            else {
            	event.handle();
            }
	    } catch (InterruptedException e) {
	    	
	    }
	}
}
